package phoenix.mob_android.page_objects;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseMobAndroidExt;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.mob_android.locators.base.FavouritesPageLocatorsBase;

public class FavouritesPage extends PageBaseMobAndroidExt
{
	/**
	 * Initializes the ChatPage
	 * @param p_manager
	 *            PhoenixManager instance
	 */
	public FavouritesPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	/**
	 * Gets web elements by site
	 * @return IndexPageLocatorsBase instance
	 */
	public FavouritesPageLocatorsBase elements()
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.mob_android.locators.flirt.FavouritesPageLocators();
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.mob_android.locators.wildbuddies.FavouritesPageLocators();
			}
			case ConfigExt.SITE_ID_CHEECKYLOVERS:
			{
				return new phoenix.mob_android.locators.cheeckylovers.FavouritesPageLocators();
			}
			default:
			{
				return null;
			}
		}
	}

	public void isOnFavouritesPage()
	{
		md().waitForPresence(elements().blockFavourites, "Favourites page doesn't appear");
	}

	public boolean checkForFriends()
	{
		md().wait(5);
		return md().isElementPresent(elements().blockFriendUser);
	}

	public String getScreennameOfFriend()
	{
		return manager.wd().driver().findElement(elements().blockUserScreenname).getText();
	}

	public FavouritesPage openProfile()
	{
		md().wait(2);
		if (md().isElementPresent(elements().blockUserProfileLoad))
		{
			md().click(elements().blockUserProfileLoad);
		}
		else if (md().isElementPresent(elements().blockUserProfileLoadInProgress))
		{
			md().click(elements().blockUserProfileLoadInProgress);
		}
		else
		{
			log().errorAndScreen("Block of user doesn't appear on My favourites page");
		}
		return this;
	}

	public FavouritesPage removeFromFavourites()
	{
		md().waitForPresence(elements().btnFavourite, "Favourite button doesn't appear");
		md().click(elements().btnFavourite);

		return this;
	}

}
